package net.borderwars.simulator.events;

import net.borderwars.map.Location;
import net.borderwars.map.Movable;
import net.borderwars.map.QuadTree;
import net.borderwars.map.Velocity;

/**
 * @author Eric
 *         Date: Mar 18, 2004
 *         Time: 6:35:53 PM
 */
public class BoundryCrossing extends BEvent {
    Movable r = null;
    QuadTree map = null;
    Location crossPoint = null;

    public BoundryCrossing (long l, Movable r, QuadTree map, Location exitPoint) {
        super (l);
        this.r = r;
        this.map = map;
        this.crossPoint = exitPoint;
    }

    public void process () {

        map.remove (r); // remove it from the map

        Location l = r.getLocation ();
        Velocity v = r.getVelocity ();
//         = (int) (crossPoint.x + v.getVX());
//        l.getY() = (int) (crossPoint.y + v.getVY());
//        // TODO: what if this little "adjustment" goes off the edge of the
//        // TODO: battleplane?
//        r.x %= 2048;
//        r.y %= 2048;
//        //System.err.println("Boundry Crossing for " + r + " @" + timeStamp + " where " + crossPoint);

        BEvent e = map.add (r); // add it back in
        if (e == null) {
            return;
        }
        eq.placeEvent (e);

    }

    public String getName () {
        return "BoundryCrossing";
    }

    public String toString () {
        return "BoundryCrossing{" + "crossPoint=" + crossPoint + ", r=" + r + "}";
    }
}
